﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dukou.Example.DTO.Domain;
using Dukou.DTO;
using Dukou.Example.DTO.DTO;
using Dukou.Example.DTO.Parsers;

namespace Dukou.Example.DTO.Test
{
    public class TestUserParser
    {
        public static void Test()
        {
            User user = new User()
            {
                Id = 1,
                UserName = "matt fang",
                Password = "123456",
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
            };

            user.Creator = user;
            user.Updator = user;

            UserDTO dto = ObjectParser.Parse<UserDTO, User, UserParser>(user, new Dictionary<string, ObjectCache>(), 0);

            user = ObjectParser.Parse<UserDTO, User, UserParser>(dto, new Dictionary<string, ObjectCache>(), 1);
        }

        public static void TestList()
        {
            IList<User> users = new List<User>();

            User user1 = new User()
            {
                Id = 1,
                UserName = "matt fang",
                Password = "123456",
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
            };

            user1.Creator = user1;
            user1.Updator = user1;
            users.Add(user1);
            users.Add(user1);

            User user2 = new User()
            {
                Id = 2,
                UserName = "celine zhu",
                Password = "123456",
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
            };
            user2.Creator = user1;
            user2.Updator = new User()
            {
                Id = 3,
                UserName = "ben fang",
                Password = "123456",
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
            };

            users.Add(user2);

            IList<UserDTO> dtos = ObjectParser.Parse<UserDTO, User, UserParser>(users, new Dictionary<string, ObjectCache>(), 0);

            users = ObjectParser.Parse<UserDTO, User, UserParser>(dtos, new Dictionary<string, ObjectCache>(), 0);
        }
    }
}
